package models

import (
	"gorm.io/gorm"
	"worklog/utils"
)

type Message struct {
	gorm.Model
	UserName    string `valid:"required,length(1|15)"`
	PassWord    string `valid:"required,length(8|16)"`
	NowDate     string `valid:"required,length(8|16)"`
	WorkContent string `valid:"required"`
	WorkTime    string `valid:"required"`
}

func (msg Message) TableName() string { return "message" }

func GetMessage() []*Message {
	data := make([]*Message, 0)
	utils.DB.Select("id", "user_name", "now_date", "work_content", "work_time").Find(&data)
	return data
}
func CreateMessage(message Message) error {
	utils.DB.Create(&message)
	return nil
}
